package com.xbh.boot_study.config;

import com.xbh.boot_study.srv.LoginSrv;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @MyWsConfig: my wsdl config
 * @author: ZBoHang
 * @time: 2022/3/16 9:56
 */
@Configuration
public class MyWsdlConfig {

    @Autowired
    private LoginSrv loginSrv;

    @Bean
    public ServletRegistrationBean<CXFServlet> dispatcher() {
        // 发布服务的跟路径,后面 * 是通配符,表示跟什么都行
        return new ServletRegistrationBean<>(new CXFServlet(), "/webservice/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    // 多个服务 可多写几个端点
    @Bean
    public Endpoint endpoint(@Qualifier(Bus.DEFAULT_BUS_ID) SpringBus springBus) {

        EndpointImpl endpoint = new EndpointImpl(springBus, loginSrv);

        endpoint.publish("/loginApi");

        return endpoint;
    }
}
